/*
 * @Description: 生成SearchVo
 * @Author: DHL
 * @Date: 2022-01-30 14:20:12
 * @LastEditors: DHL
 * @LastEditTime: 2022-10-10 17:03:19
 */

import { firstToLowerCase, firstToUpperCase } from '../../../utils/codeGenUtils'

export function createSearchVo(codeGenConfig: any) {
  const classNameFirstToLowerCase = firstToLowerCase(codeGenConfig.className)
  const className = 'Search' + codeGenConfig.className + 'Vo'
  codeGenConfig.genName = codeGenConfig.genName + ' - 查询入参'

  return `
package ${codeGenConfig.packageName}.entity.${classNameFirstToLowerCase}.vo;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.twb.core.base.entity.vo.PageVo;
import com.twb.core.util.DateUtil;
import com.twb.core.money.MoneyFormat;

import java.math.BigDecimal;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @ClassName: ${className}
 * @Description: ${codeGenConfig.genName}
 * 
 * @author ${codeGenConfig.genAuthor}
 * @date ${codeGenConfig.createData}
 */
@ApiModel(value = "${className}", description = "${codeGenConfig.genName}")
public class ${className} extends PageVo implements Serializable {
  private static final long serialVersionUID = 1L;

  ${getField(codeGenConfig.optionsJson.columns)}

  /** 关键字模糊查询 */
  @ApiModelProperty(value = "关键字模糊查询")
  private String queryLikeStr;
  
  ${getMethod(codeGenConfig.optionsJson.columns)}

  /** 关键字模糊查询 */
  public String getQueryLikeStr() {
    return queryLikeStr;
  }
  /** 关键字模糊查询 */
  public void setQueryLikeStr(String queryLikeStr) {
    this.queryLikeStr = queryLikeStr;
  }
}
`
}

/**
 * 获取主键字段
 * @param columns
 */
function getField(columns: any) {
  let field: Array<string> = []

  columns.forEach((item: any) => {
    if (item.query) {
      if (item.queryWay === 'between') {
        const tempBegin = [
          `
  /** ${item.javaComment} - 开始 */`
        ]

        const tempEnd = [
          `
  /** ${item.javaComment} - 结束 */`
        ]

        // 金额类型
        if (item.componentType === 'money') {
          tempBegin.push(`
  @MoneyFormat`)

          tempEnd.push(`
  @MoneyFormat`)
        }

        tempBegin.push(`
  @ApiModelProperty(value = "${item.javaComment} - 开始")
  private ${item.javaType} ${item.javaField}Begin;
      `)

        tempEnd.push(`
  @ApiModelProperty(value = "${item.javaComment} - 结束")
  private ${item.javaType} ${item.javaField}End;
      `)

        field.push(tempBegin.join(''))
        field.push(tempEnd.join(''))
      } else {
        const temp = [
          `
  /** ${item.javaComment} */`
        ]

        // 金额类型
        if (item.componentType === 'money') {
          temp.push(`
  @MoneyFormat`)
        }

        temp.push(`
  @ApiModelProperty(value = "${item.javaComment}")
  private ${item.javaType} ${item.javaField};
      `)

        field.push(temp.join(''))
      }
    }
  })
  return field.join('')
}

/**
 * 获取方法
 * @param columns
 */
function getMethod(columns: any) {
  let method: Array<string> = []

  columns.forEach((item: any) => {
    if (item.query) {
      if (item.queryWay === 'between') {
        method.push(
          `
  /** ${item.javaComment} - 开始 */
  public ${item.javaType} get${firstToUpperCase(item.javaField)}Begin() {
    return ${item.javaField}Begin;
  }
  /** ${item.javaComment} - 开始 */
  public void set${firstToUpperCase(item.javaField)}Begin(${item.javaType} ${item.javaField}Begin) {
    this.${item.javaField}Begin = ${item.javaField}Begin;
  }

  /** ${item.javaComment} - 结束 */
  public ${item.javaType} get${firstToUpperCase(item.javaField)}End() {
      return ${item.javaField}End;
  }
  /** ${item.javaComment} - 结束 */
  public void set${firstToUpperCase(item.javaField)}End(${item.javaType} ${item.javaField}End) {
    this.${item.javaField}End = ${item.javaField}End;
  }
  `
        )
      } else {
        method.push(
          `
  /** ${item.javaComment} */
  public ${item.javaType} get${firstToUpperCase(item.javaField)}() {
    return ${item.javaField};
  }
  /** ${item.javaComment} */
  public void set${firstToUpperCase(item.javaField)}(${item.javaType} ${item.javaField}) {
    this.${item.javaField} = ${item.javaField};
  }
  `
        )
      }
    }
  })
  return method.join('')
}
